//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package cn.hx.mall.sell.controller;

import cn.hx.mall.order.entity.PageModel;
import cn.hx.mall.sell.entity.SmsHomeRecommendSubject;
import cn.hx.mall.sell.service.SmsHomeRecommendSubjectService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping({"sell"})
public class SmsHomeRecommendSubjectController {
    @Resource
    private SmsHomeRecommendSubjectService smsHomeRecommendSubjectService;
    private SmsHomeRecommendSubject smsHomeRecommendSubject;

    public SmsHomeRecommendSubjectController() {
    }

    @GetMapping({"recommend"})
    public String findAll(@RequestParam(defaultValue="1") int page, Model model,@RequestParam(defaultValue="5") int size) {
        PageModel<SmsHomeRecommendSubject> pageModel = PageModel.getInstance(page,size);
        pageModel.setPage(page);
        pageModel.setList(smsHomeRecommendSubjectService.queryAllByLimit((page-1)*size,size));
        pageModel.setSize(size);
        int count = smsHomeRecommendSubjectService.count();
        pageModel.setPageSize(count%size==0?count/size:count/size+1);
        pageModel.setCount(count);
        model.addAttribute("pageMadel",pageModel);
        return "sell/recommend";
    }

    @GetMapping({"deleteByRecommendProjectId/{id}"})
    public String delete(@RequestParam(defaultValue="1") int page, Model model,@RequestParam(defaultValue="5") int size,@PathVariable Long id) {
        this.smsHomeRecommendSubjectService.deleteById(id);
        PageModel<SmsHomeRecommendSubject> pageModel = PageModel.getInstance(page,size);
        pageModel.setPage(page);
        pageModel.setList(smsHomeRecommendSubjectService.queryAllByLimit((page-1)*size,size));
        pageModel.setSize(size);
        int count = smsHomeRecommendSubjectService.count();
        pageModel.setPageSize(count%size==0?count/size:count/size+1);
        pageModel.setCount(count);
        model.addAttribute("pageMadel",pageModel);
        return "sell/recommend";
    }

    @GetMapping({"/addRecommendProject"})
    public String add() {
        return "sell/addRecommendProject";
    }

    @PostMapping({"/addRecommendProject"})
    public String brand(@RequestParam(defaultValue="1") int page, Model model,@RequestParam(defaultValue="5") int size, SmsHomeRecommendSubject smsHomeRecommendSubject) {
        this.smsHomeRecommendSubjectService.insert(smsHomeRecommendSubject);
        PageModel<SmsHomeRecommendSubject> pageModel = PageModel.getInstance(page,size);
        pageModel.setPage(page);
        pageModel.setList(smsHomeRecommendSubjectService.queryAllByLimit((page-1)*size,size));
        pageModel.setSize(size);
        int count = smsHomeRecommendSubjectService.count();
        pageModel.setPageSize(count%size==0?count/size:count/size+1);
        pageModel.setCount(count);
        model.addAttribute("pageMadel",pageModel);
        return "sell/recommend";
    }


     @GetMapping({"recommend_1"})
     @ResponseBody
     public PageInfo<SmsHomeRecommendSubject> findAll1(SmsHomeRecommendSubject smsHomeRecommendSubject, @RequestParam(defaultValue="1") int page) {
         Page<SmsHomeRecommendSubject> objects = PageHelper.startPage(page, 5);
         smsHomeRecommendSubjectService.findAll(smsHomeRecommendSubject);
         return new PageInfo<>(objects);
     }

    @GetMapping({"setRecommendProjectSort"})
    public String set(Long id, Model model) {
        SmsHomeRecommendSubject smsHomeRecommendSubject = this.smsHomeRecommendSubjectService.queryById(id);
        Integer sort = smsHomeRecommendSubject.getSort();
        model.addAttribute("sort", sort);
        model.addAttribute("subject", smsHomeRecommendSubject);
        return "sell/updateSubjectSort";
    }

    @PostMapping({"/updateRecommendSubjectSort"})
    public String update_sort(SmsHomeRecommendSubject smsHomeRecommendSubject,@RequestParam(defaultValue="1") int page, Model model,@RequestParam(defaultValue="5") int size) {
        this.smsHomeRecommendSubjectService.update(smsHomeRecommendSubject);
        PageModel<SmsHomeRecommendSubject> pageModel = PageModel.getInstance(page,size);
        pageModel.setPage(page);
        pageModel.setList(smsHomeRecommendSubjectService.queryAllByLimit((page-1)*size,size));
        pageModel.setSize(size);
        int count = smsHomeRecommendSubjectService.count();
        pageModel.setPageSize(count%size==0?count/size:count/size+1);
        pageModel.setCount(count);
        model.addAttribute("pageMadel",pageModel);
        return "sell/recommend";
    }

    @GetMapping({"/changeStatus"})
    @ResponseBody
        public PageInfo<SmsHomeRecommendSubject> changeStatus(SmsHomeRecommendSubject smsHomeRecommendSubject, Integer GetRecommendStatus, Integer page) {
        SmsHomeRecommendSubject NewSmsHomeRecommendSubject = new SmsHomeRecommendSubject();
        BeanUtils.copyProperties(smsHomeRecommendSubject,NewSmsHomeRecommendSubject);
        smsHomeRecommendSubject.setSubjectName(null);
        NewSmsHomeRecommendSubject.setRecommendStatus(GetRecommendStatus);
        NewSmsHomeRecommendSubject.setId(null);
        smsHomeRecommendSubjectService.update(smsHomeRecommendSubject);
        Page<SmsHomeRecommendSubject> startPage = PageHelper.startPage(page, 5);
        smsHomeRecommendSubjectService.findAll(NewSmsHomeRecommendSubject);
        return new PageInfo<SmsHomeRecommendSubject>(startPage);
    }
}
